using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor.Document;
using CodeGenerator;
using CodeGenerator.Classes;
using System.Globalization;

namespace CodeGenerator
{
    public partial class frmEntities : Form
    {
        public static string lConnectionString = "";
        public static string lDataBase = "";

        public frmEntities()
        {
            InitializeComponent();
        }

        public frmEntities(string ConnStr, string DB)
        {
            InitializeComponent();

            lConnectionString = ConnStr;
            lDataBase = DB;

            CreateTree();

        }

        private void CreateTree()
        {
            CodeGenerator.Classes.DataBaseInformation DI = new CodeGenerator.Classes.DataBaseInformation(lConnectionString);
            for (int i = 0; i < DI.LoadTable().Count; i++)
            {

                listBox1.Items.Add(DI.LoadTable()[i].ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > -1)
            {
                string _text = listBox1.Text;  // Gets the Text of items in the list.  
               
                listBox2.Items.Add(_text); //Add the list item to the selected list of employees   

                listBox1.Items.Remove(_text); //Remove the details from employee list   

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex > -1)
            {
                string _text = listBox2.Text;  // Gets the Text of items in the list.  

                listBox1.Items.Add(_text); //Add the list item to the selected list of employees   

                listBox2.Items.Remove(_text); //Remove the details from employee list   

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int _count = listBox1.Items.Count;
            if (_count != 0)
            {
                for (int i = 0; i < _count; i++)
                {
                 
                    string item = listBox1.Items[i].ToString();
                    listBox2.Items.Add(item);
                }
            }

            listBox1.Items.Clear();//clear the items  
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int _count = listBox2.Items.Count;
            if (_count != 0)
            {
                for (int i = 0; i < _count; i++)
                {
                    string item = listBox2.Items[i].ToString();
                    listBox1.Items.Add(item);
                }
            }

            listBox2.Items.Clear();//clear the items  
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < listBox2.Items.Count; i++)
                {
                    Classes.File f = new CodeGenerator.Classes.File();
                    Classes.GeneratorEntities c = new CodeGenerator.Classes.GeneratorEntities(lConnectionString, listBox2.Items[i].ToString());

                    GeneratorEntities.NameSpace = txtProjek.Text;

                    f.Save(PropCaseStartLower(listBox2.Items[i].ToString()).Replace("_", ""), textBox1.Text, c.GeneratEntities(), "cs");

                }

                MessageBox.Show("Berhasil...");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }

        public string PropCaseStartLower(string strText)
        {
            string retVal = PropCase(strText);
            retVal = retVal.Substring(0, 1).ToLower() + retVal.Substring(1, (retVal.Length - 1));
            return retVal;
        }

        public string PropCase(string strText)
        {
            return new CultureInfo("en").TextInfo.ToTitleCase(strText.ToLower());
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }


        private void Utama_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Hide();
        }


    }
}